package com.probiz.estore.common.model.order;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.common.model.customer.Address;
import com.probiz.estore.common.model.order.base.OrderAddressTbl;

/**
 * Model class for OrderAddress. Add not database mapped fileds in this class.
 */
public class OrderAddress extends OrderAddressTbl implements Cloneable{

  	/**
	 * Default Empty Constructor for class OrderAddress
	 */
	public OrderAddress () {
		super();
	}
	
	/**
	 * 定义实体的业务名取值； orderAddressName
	 * 必须手工完成这个部分，否则编译不通过。
	 */
	public String getOrderAddressName () {
		if (orderAddressId == null)
	        return "";
	    else
			//返回一个指定有业务意义的属性值;
			//如：product的VO就用product.productName
	        return this.getAddress1();
	}
	
	/**
	 * Default Key Fields Constructor for class OrderAddress
	 */
	public OrderAddress (
		 Integer in_orderAddressId
		) {
		super (
		  in_orderAddressId
		);
	}
	/**
	 * 深复制
	 */
	public OrderAddress clone(){
		OrderAddress oa = new OrderAddress();
		oa.setAddress1(this.getAddress1());
		oa.setAddress2(this.getAddress2());
		oa.setFaxNumber(this.getFaxNumber());
		oa.setFirstname(this.getFirstname());
		oa.setLastname(this.getLastname());
		oa.setPhoneNumber(this.getPhoneNumber());
		oa.setPostalcode(this.getPostalcode());
		oa.setRegionId(this.getRegionId());
		oa.setRegionFullName(this.getRegionFullName());
		try {
			super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return oa;
	}
	
	/**
	 * 应用传入地址对象的值到自身
	 * @param address
	 */
	public void applyAddress(Address address) {
		this.setFirstname(address.getFirstname());
		this.setAddress1(address.getAddress());
		this.setPhoneNumber(address.getTelephone());
		this.setPostalcode(address.getZip());
		this.setRegionId(address.getRegionId());
		this.setRegionFullName(address.getRegionFullName());
		this.setEmail(address.getEmail());
	}
	
	/**
	 * 是否虚拟地址---对应的订单或者发退货单中只有礼券
	 * @return
	 */
	public boolean getIsVirtual(){ 
		if(StringUtils.isBlank(this.regionFullName) && StringUtils.isBlank(this.getAddress1())){
			return true;
		}else{
			return false; 
		}
	}
	
	

}
